home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / boosters.arc / OVERSTR.ASM < prev    next >
Assembly Source File  |  1985-09-29  |  3KB  |  134 lines

  1. ;***********************************************
  2. ;
  3. ;       FUNCTION OVERSTR   (NEW,
  4. ;                           TARGET : AnyString;
  5. ;                           N,LEN  : Integer;
  6. ;                           PAD    : Char)
  7. ;                                  : AnyString;
  8. ;
  9. ;       Description:
  10. ;               Returns a string with NEW
  11. ;               overlayed on TARGET,
  12. ;               beginning at position N of
  13. ;               TARGET, for length LEN.
  14. ;               If N > Length(Target), or if
  15. ;               LEN > Length(New), the result
  16. ;               is padded accordingly.
  17. ;
  18. ;       Examples:
  19. ;               OverStr('123','ABCD',2,2,' ')
  20. ;               would return 'A12D'.
  21. ;
  22. ;               OverStr('123',ABCD',6,6,'_')
  23. ;               would return 'ABCD_123___'.
  24. ;***********************************************
  25. OVERSTR Proc
  26.     push    bp
  27.     mov    bp,sp
  28.     push    ds
  29. ;
  30. ;***    set registers for string moves on the stack
  31. ;
  32.     mov    ax,ss
  33.     mov    es,ax
  34.     mov    ds,ax
  35. ;
  36. ;***    move target string to result
  37. ;
  38.     mov    cl,[bp+10]    ; l'target
  39.     xor    ch,ch
  40.     lea    si,[bp+11]    ; A(target)
  41.     lea    di,[bp+523]    ; A(result)
  42.     cld
  43. rep    movsb            ; target to result
  44. ;
  45. ;***    if N or LEN <= 0, result = target
  46. ;
  47.     mov    bl,[bp+10]    ; l' target
  48.     xor    bh,bh
  49.     mov    cx,[bp+6]    ; LEN
  50.     cmp    cx,0
  51.     jl    e020
  52.     mov    dx,[bp+8]    ; N
  53.     cmp    dx,0
  54.     jl    e020
  55. ;
  56. ;***    If N > Length(Target) + 1 then
  57. ;***    compute amount of PAD to insert
  58. ;
  59.     lea    di,[bp+523]    ; A(l'result)
  60.     cmp    dx,bx        ; N> l'target?
  61.     jna    e010
  62. ;
  63. ;***    if N > 255, then N = 255
  64. ;
  65.     cmp    dx,0FFh
  66.     jbe    e005
  67.     mov    dx,100h
  68. ;
  69. e005:    mov    cx,dx
  70.     sub    cx,bx        ; N-l'target
  71.     dec    cx
  72.     mov    ax,[bp+4]    ; pad
  73.     add    di,bx        ; point past target
  74. rep    stosb
  75.     lea    di,[bp+523]
  76. ;
  77. ;***    Adjust CX to point to address of
  78. ;***    result where NEW will appear
  79. ;
  80.     mov    cx,[bp+6]    ; LEN
  81.     add    cx,dx        ; LEN+N
  82.     cmp    cx,0FFh
  83.     ja    e007
  84.     mov    cx,[bp+6]
  85.     jmp    e010
  86. ;
  87. e007:    mov    cx,0FFh
  88.     sub    cx,dx
  89.     inc    cx        ; adj LEN
  90. ;
  91. ;***    Copy NEW to result
  92. ;
  93. e010:    mov    al,[bp+266]    ; l'new
  94.     xor    ah,ah
  95.     push    cx
  96.     cmp    cx,ax        ; LEN > l'new?
  97.     jb    e015
  98.         mov     cx,ax
  99. e015:    lea    si,[bp+267]    ; A(new)
  100.     add    di,dx        ; begin at N
  101.     dec    di
  102. rep    movsb            ; move NEW
  103. ;
  104. ;***    If LEN > length(NEW) then PAD
  105. ;
  106.     pop    cx        ; LEN
  107.     cmp    cx,ax        ; LEN > l'new?
  108.     jbe    e020
  109.     add    ax,dx        ; N + l'new
  110.     cmp    ax,0FFh
  111.     jnb    e020
  112.     push    cx
  113.     mov    al,[bp+266]    ; l'new
  114.     xor    ah,ah
  115.     sub    cx,ax        ; LEN-l'new
  116.     mov    ax,[bp+4]    ; pad byte
  117. rep    stosb
  118.     pop    cx
  119. ;
  120. ;***    Set the length of the result string
  121. ;
  122. e020:    lea    cx,[bp+523]
  123.     sub    di,cx
  124.     cmp    di,bx
  125.     ja    e025
  126.     mov    di,bx
  127. e025:    mov    ax,di
  128.     mov    [bp+522],al    ; l'result
  129. ;
  130.     pop    ds
  131.     mov    sp,bp
  132.     pop    bp
  133.     ret    518
  134. OVERSTR endp